/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "programtexttransfer.h"
#include "instructionEnum.h"
#include <qdebug.h>
#include "pathdefine.h"
#include <QStringList>
#ifdef D_USE_FOR_CONTROLLER
#include "messagelog.h"
#endif


ProgramTextTransfer::ProgramTextTransfer(int robotIdIn)
{
    robotId=robotIdIn;
}


int ProgramTextTransfer::readProgramVersionInfo(QVector <QString> fileInfoList,QString &versionOut)
{
   versionOut.clear();
   QString capStr;
   for(int i = 0;i < fileInfoList.size();i++)
   {
       QString str = fileInfoList[i];
       if(fileInfoList[i].startsWith("VERSION"))
       {
           QString pattern("\\s*(VERSION)\\s*(=)\\s*(\\w*)\\s*(.*)");
           QRegExp rx(pattern);
           str.indexOf(rx);
           if("VERSION" == rx.cap(1))
           {
               capStr = rx.cap(3);
               versionOut= capStr;
               return 1;
           }
       }
    }

    return -1;
}


int ProgramTextTransfer::getDpoint(std::string fileName, int pointIndex, DPoint &pointOut)
{

    if( fileName.size() <= 0 )
    {
       // qDebug()<<"程式名为空 readProgram（？）"<<strFilePath;
      //  addMsg( 0, "ProgramEngine", "ProgramEngine",  3008, robotId   );
        return -1;
    }
    QString strFilePath = "";
    strFilePath = QString(D_TCRCONTROLLER_DATA_PATH)+QString(ROBOT_COMMON_NAME) + QString::number(robotId) + QString(ROBOT_PROGRAM_FLODER) + fileName.data();
    QFile file(strFilePath);
    if( !file.exists() )
    {
       // qDebug()<<"程式文件不存在 readProgram（？）"<<strFilePath;
       // addMsg( 0, "ProgramEngine", "ProgramEngine",  3009, robotId   );
        return -2;
    }

    QString lineStr = "";
    QVector<QString> fileInfoList;//文件每行内容
    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        file.reset();
        QTextStream in(&file);

        while(!in.atEnd())
        {
            lineStr = in.readLine();
            fileInfoList.append(lineStr);
        }

        if(readProgramDPointData(fileInfoList,pointIndex,pointOut)==1)
        {
            //找到指定索引的点
        }
        else
        {
            //未找到指定索引的点
            return -3;
        }
    }
    else
    {
        //文件打开失败
        return -4;
    }

    //todo
    return 1;
}

int ProgramTextTransfer::recordDpoint(std::string fileName, DPoint pointIn)
{

    int stateValue = 0;
    if( fileName.size() <= 0 )
    {
      // qDebug()<<"程式名为空 readProgram（？）"<<fileName;
      //  addMsg( 0, "ProgramEngine", "ProgramEngine",  3008, robotId   );
        return 0;
    }
    QString strFilePath = "";
    strFilePath = QString(D_TCRCONTROLLER_DATA_PATH)+QString(ROBOT_COMMON_NAME) + QString::number(robotId) + QString(ROBOT_PROGRAM_FLODER) + fileName.data();
    QFile file(strFilePath);
    if( !file.exists() )
    {
       qDebug()<<"程式文件不存在 readProgram（？）"<<strFilePath;
       // addMsg( 0, "ProgramEngine", "ProgramEngine",  3009, robotId   );
        return 0;
    }

    do
    {
        QString lineStr = "";
        QVector<QString> fileInfoList;//文件每行内容
        if(file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            file.reset();
            QTextStream in(&file);

            while(!in.atEnd())
            {
                lineStr = in.readLine();
                fileInfoList.append(lineStr);
            }

            if(addProgramDPointData(fileInfoList,pointIn)==1)
            {
                //成功加入指定索引的点


                file.close();

                if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
                {
                    QTextStream out(&file);
                    for(int j = 0;j<fileInfoList.size();j++)
                    {
                        out << fileInfoList[j]<<"\n";
                    }
                    file.flush();
                    file.close();
                    stateValue=1;
                }

            }
            else
            {
                file.flush();
                //未找到指定索引的点
                return 0;
                break;
            }
        }
        else
        {
            //文件打开失败
            return 0;
            break;
        }

    }while(0);


    //todo
    int tmpVersion;
    readAndWriteProgramFileVersion(strFilePath,tmpVersion);
    return stateValue;
}

int ProgramTextTransfer::transferText(QString strFilePath, QVector <QString>& cmdStrList_out
             , QVector <PointPro>& pointList_out, QVector <PlRegStruct>& regPlList_out
             , QVector <StackInfo>& palletStackInfo_out, QMap<int, DPoint> &vehicleDPointListOut,
                                      QString &versionOut)
{
    fileName=strFilePath.section("/",8,8);//not good
    if( strFilePath.isEmpty() )
    {
        qDebug()<<"程式名为空 readProgram（？）"<<strFilePath;
        addMsg( 0, "ProgramEngine", "ProgramEngine",  3008, robotId   );
        return -1;
    }

    QFile file(strFilePath);
    if( !file.exists() )
    {
        qDebug()<<"程式文件不存在 readProgram（？）"<<strFilePath;
        addMsg( 0, "ProgramEngine", "ProgramEngine",  3009, robotId   );
        return -2;
    }

    QVector <QString> fileInfoList;//文件每行内容
    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        file.reset();
        QTextStream in(&file);
        QString lineStr;
        while(!in.atEnd())
        {
            lineStr = in.readLine();
            fileInfoList.append(lineStr);
        }
    }
    else
    {
        //消息预留
        //文件打开失败
        addMsg( 0,  "ProgramEngine", "ProgramEngine",  3508,  robotId);
        return -3;
    }

    file.close();
    file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    //解析文件
    FileInfo  fileProInfo;
    QStringList tmp_StrList;
    int tmpKey=readProgram(fileInfoList, fileName,fileProInfo,palletStackInfo_out,
                           pointList_out,tmp_StrList,
                           vehicleDPointListOut);

    if(1!=tmpKey)
    {
        addMsg( 0, "ProgramEngine", "ProgramEngine",  3507, robotId );
        return -4;
    }
    cmdStrList_out.resize(tmp_StrList.size());
    for(int i=0;i<tmp_StrList.size();i++)
    {
        cmdStrList_out[i]=tmp_StrList[i];
    }
    versionOut=QString::fromStdString(fileProInfo.version);

//    #ifdef D_USE_ROS
    readProgramDPointData(fileInfoList, vehicleDPointListOut);
//    #endif


    return 1;

}

int ProgramTextTransfer::readAndWriteProgramFileVersion(QString strFilePath, int &newVersionOut)
{
    fileName=strFilePath.section("/",8,8);//not good
    if( strFilePath.isEmpty() )
    {
        qDebug()<<"程式名为空 readProgram（？）"<<strFilePath;
        addMsg( 0, "ProgramEngine", "ProgramEngine",  3008, robotId   );
        return -1;
    }

    QFile file(strFilePath);
    if( !file.exists() )
    {
        qDebug()<<"程式文件不存在 readProgram（？）"<<strFilePath;
        addMsg( 0, "ProgramEngine", "ProgramEngine",  3009, robotId   );
        return -2;
    }


    QVector <QString> fileInfoList;//文件每行内容


    if(false==file.open(QIODevice::ReadWrite | QIODevice::Text))
    {
       return -3;
    }
    file.reset();
    QTextStream in(&file);
    QString lineStr;
    while(!in.atEnd())
    {
        lineStr = in.readLine();
        fileInfoList.append(lineStr);
    }


    QString tmpVersion;
    QString capStr;
    for(int i = 0;i < fileInfoList.size();i++)
    {
        QString str = fileInfoList[i];
        if(fileInfoList[i].startsWith("VERSION"))
        {
            QString pattern("\\s*(VERSION)\\s*(=)\\s*(\\w*)\\s*(.*)");
            QRegExp rx(pattern);
            str.indexOf(rx);
            if("VERSION" == rx.cap(1))
            {
                capStr = rx.cap(3);
                tmpVersion= capStr;
                fileInfoList[i]="VERSION =";
                newVersionOut=tmpVersion.toInt()+1;
                fileInfoList[i]+=QString::number(newVersionOut)+" ;";
                qDebug()<<"newVersionOut="<<newVersionOut;
            }
        }
     }


    //写文件
    file.resize(0);
    QTextStream in_new(&file);
    for(int i = 0;i < fileInfoList.size();i++)
    {
        if(fileInfoList[i].contains("\n"))
        {
            fileInfoList[i].replace("\n","");
        }
//            qDebug() << "*****"<<__FUNCTION__<<"****"<<__LINE__<<"**programList***"<<programList[i]<<endl;
        in_new << fileInfoList[i]<<"\n";
    }
    file.close();
    file.flush();

    return 1;


}

int ProgramTextTransfer::readProgramDPointData(const QVector<QString>& fileInfoList, QMap<int, DPoint> &vehicleDPointListOut)
{
    bool match;
    QString dPointPat;
    QRegExp rxDPoint;
    DPoint dPointTemp;
    // 每次读取文件清空容器，以保存新数据
    vehicleDPointListOut.clear();

    for(int i = 0; i < fileInfoList.size(); i++)
    {
        if((fileInfoList[i].contains("DP[")) && (fileInfoList[i].contains("]{")) )
        {
            dPointPat = "\\s*(DP\\[(\\d+)\\])(\\{)";                    //  DP[]{
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.dpIndex = rxDPoint.cap(2).toInt();
            }
        }
        else if(fileInfoList[i].contains("MapName"))
        {
            dPointPat = "\\s*(MapName)\\s*(:)\\s*(.*)\\s*";             // MapName :
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.mapName = rxDPoint.cap(3).trimmed().toStdString();
            }
        }
        else if(fileInfoList[i].contains("Type"))
        {
             dPointPat = "\\s*(Type)\\s*(:)\\s*(\\S*)\\s*";
             rxDPoint.setPattern(dPointPat);

             if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
             {
                if(rxDPoint.cap(3) == "VMark-Point")
                {
                     dPointTemp.pointType = EM_MOVE_FREE_VMARK;
                 }
                  else if(rxDPoint.cap(3) == "QR-Code-Point")
                 {
                       dPointTemp.pointType = EM_MOVE_FREE_QR;
                 }
                 else if(rxDPoint.cap(3) == "Ordinary-Point")
                 {
                       dPointTemp.pointType = EM_MOVE_FREE_DP;
                 }
                else if(rxDPoint.cap(3) == "CU1-Point")
                {
                      dPointTemp.pointType = EM_MOVE_FREE_CU1;
                }
             }
        }
        else if( (fileInfoList[i].contains("X")) && (fileInfoList[i].contains("mm")) )
        {
            dPointPat = "\\s*(X)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(mm)";      // X = ... mm
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posX = rxDPoint.cap(3).toDouble();
            }
        }
        else if( (fileInfoList[i].contains("Y")) && (fileInfoList[i].contains("mm")))
        {
            dPointPat = "\\s*(Y)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(mm)";      // Y = ... mm
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posY = rxDPoint.cap(3).toDouble();
            }
        }
        else if( (fileInfoList[i].contains("R")) && (fileInfoList[i].contains("deg")) )
        {
            dPointPat = "\\s*(R)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(deg)";     // R = ... deg
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posR = rxDPoint.cap(3).toDouble();
                vehicleDPointListOut.insert(dPointTemp.dpIndex, dPointTemp);
            }
        }
    }



    return 1;
}

int ProgramTextTransfer::readProgramDPointData(const QVector<QString>& fileInfoList,int pointIndexIn, DPoint &vehicleDPointListOut)
{
    int attrStart,tcdStart, tcdEnd, applStart,commandStart,positionStart, endLine;
    if(1!=readProgramFileStruct(fileInfoList,attrStart,tcdStart, tcdEnd,
                          applStart,commandStart,positionStart, endLine))
    {
        qDebug()<<"ProgramTextTransfer::readProgramDPointData failed, file is error!!!";
        return -1;
    }

    //errorCode 0 未找到指定索引的点　1 找到指定索引的点
    int errorCode = 0;
    bool match;
    QString dPointPat;
    QRegExp rxDPoint;
    DPoint dPointTemp;
    vehicleDPointListOut.dpIndex=0;
    vehicleDPointListOut.mapName="";
    vehicleDPointListOut.posX=0.0;
    vehicleDPointListOut.posY=0.0;
    vehicleDPointListOut.posR=0.0;

    // 每次读取文件清空容器，以保存新数据
    for(int i = positionStart; i < fileInfoList.size(); i++)
    {
        if((fileInfoList[i].contains("DP[")) && (fileInfoList[i].contains("]{")) )
        {
            dPointPat = "\\s*(DP\\[(\\d+)\\])(\\{)";                    //  DP[]{
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.dpIndex = rxDPoint.cap(2).toInt();
                if(dPointTemp.dpIndex == pointIndexIn)
                {
                    errorCode = 1;
                }
                else
                {
                    continue;
                }
            }
            else
            {
                continue;
            }
        }
        else if(fileInfoList[i].contains("MapName"))
        {
            dPointPat = "\\s*(MapName)\\s*(:)\\s*(.*)\\s*";             // MapName :
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.mapName = rxDPoint.cap(3).trimmed().toStdString();

            }
        }
        else if(fileInfoList[i].contains("Type"))
        {
             dPointPat = "\\s*(Type)\\s*(:)\\s*(\\S*)\\s*";
             rxDPoint.setPattern(dPointPat);

             if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
             {
                if(rxDPoint.cap(3)=="VMark-Point")
                {
                    dPointTemp.pointType = EM_MOVE_FREE_VMARK;
                }
                else if(rxDPoint.cap(3) == "QR-Code-Point")
                {
                   dPointTemp.pointType = EM_MOVE_FREE_QR;
                }
                else if(rxDPoint.cap(3) == "Ordinary-Point")
                {
                   dPointTemp.pointType = EM_MOVE_FREE_DP;
                }
                else if(rxDPoint.cap(3) == "CU1-Point")
                {
                     dPointTemp.pointType = EM_MOVE_FREE_CU1;
                }
             }
        }
        else if( (fileInfoList[i].contains("X")) && (fileInfoList[i].contains("mm")) )
        {
            dPointPat = "\\s*(X)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(mm)";      // X = ... mm
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posX = rxDPoint.cap(3).toDouble();
            }
        }
        else if( (fileInfoList[i].contains("Y")) && (fileInfoList[i].contains("mm")))
        {
            dPointPat = "\\s*(Y)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(mm)";      // Y = ... mm
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posY = rxDPoint.cap(3).toDouble();
            }
        }
        else if( (fileInfoList[i].contains("R")) && (fileInfoList[i].contains("deg")) )
        {
            dPointPat = "\\s*(R)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(deg)";     // R = ... deg
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posR = rxDPoint.cap(3).toDouble();

            }
        }
        else if( fileInfoList[i].contains("};"))
        {
            //找到點
            if((errorCode == 1) && (pointIndexIn==dPointTemp.dpIndex))
            {
                vehicleDPointListOut = dPointTemp;
                break;
            }
        }

    }

    return errorCode;
}

int ProgramTextTransfer::addProgramDPointData(QVector<QString> &fileInfoList,DPoint vehicleDPointIn)
{
    int attrStart,tcdStart, tcdEnd, applStart,commandStart,positionStart, endLine;
    if(1!=readProgramFileStruct(fileInfoList,attrStart,tcdStart, tcdEnd,
                          applStart,commandStart,positionStart, endLine))
    {
        qDebug()<<"ProgramTextTransfer::readProgramDPointData failed, file is error!!!";
        return -1;
    }

    //errorCode 0 未找到指定索引的点　1 找到指定索引的点
    int errorCode = 0;
    bool match;
    QString dPointPat;
    QRegExp rxDPoint;
    DPoint dPointTemp;
    int recordFrontIndex = -1;
    int findPoint = -1;
    int endIndex = -1;
    // 每次读取文件清空容器，以保存新数据
    for(int i = positionStart; i < fileInfoList.size(); i++)
    {
        if((fileInfoList[i].contains("DP[")) && (fileInfoList[i].contains("]{")) )
        {
            dPointPat = "\\s*(DP\\[(\\d+)\\])(\\{)";                    //  DP[]{
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.dpIndex = rxDPoint.cap(2).toInt();
                if(dPointTemp.dpIndex == vehicleDPointIn.dpIndex)
                {

                    findPoint = i;
                    break;
                }
                else if(dPointTemp.dpIndex < vehicleDPointIn.dpIndex)
                {
                    recordFrontIndex = i;
                }
                else if(dPointTemp.dpIndex > vehicleDPointIn.dpIndex)
                {
                    break;
                }
            }

        }
        else
        {
            if(fileInfoList[i].contains("/END"))
            {
                endIndex = i;
            }

        }
    }

    if(findPoint != -1)
    {
        //在文件中找到指定的点
        QString vcDataItem = "";
        int pointIndexTmp = findPoint;
        vcDataItem = QString("DP[%1]{").arg(vehicleDPointIn.dpIndex);
        fileInfoList.replace(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("  MapName :%s",vehicleDPointIn.mapName.data());
        fileInfoList.replace(pointIndexTmp,vcDataItem);

        pointIndexTmp++;
        if(vehicleDPointIn.pointType == EM_MOVE_FREE_DP)
        {
            vcDataItem.sprintf("  Type :%s","Ordinary-Point");
        }
        else if(vehicleDPointIn.pointType == EM_MOVE_FREE_QR)
        {
            vcDataItem.sprintf("  Type :%s","QR-Code-Point");
        }
        else if(vehicleDPointIn.pointType == EM_MOVE_FREE_VMARK)
        {
            vcDataItem.sprintf("  Type :%s","VMark-Point");
        }
        else if(vehicleDPointIn.pointType == EM_MOVE_FREE_CU1)
        {
            vcDataItem.sprintf("  Type :%s","CU1-Point");
        }
        fileInfoList.replace(pointIndexTmp,vcDataItem);

        pointIndexTmp++;
        vcDataItem.sprintf("      X = %s mm",QString::number(vehicleDPointIn.posX, 10, 3).toStdString().data());
        fileInfoList.replace(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("      Y = %s mm",QString::number(vehicleDPointIn.posY, 10, 3).toStdString().data());
        fileInfoList.replace(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("      R = %s deg",QString::number(vehicleDPointIn.posR, 10, 3).toStdString().data());
        fileInfoList.replace(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem = QString("};");
        fileInfoList.replace(pointIndexTmp,vcDataItem);
        errorCode = 1;
    }
    else
    {
        //没有在文件中找到指定的点
        QString vcDataItem = "";
        int pointIndexTmp = -1;
        if(recordFrontIndex != -1)
        {
            pointIndexTmp = recordFrontIndex;
            pointIndexTmp += 7;
        }
        else
        {
            pointIndexTmp = endIndex;
        }
        if(pointIndexTmp == -1)
        {
            pointIndexTmp = fileInfoList.size()-1;
        }
        vcDataItem = QString("DP[%1]{").arg(vehicleDPointIn.dpIndex);
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("  MapName :%s",vehicleDPointIn.mapName.data());
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        if(vehicleDPointIn.pointType == EM_MOVE_FREE_DP)
        {
            vcDataItem.sprintf("  Type :%s","Ordinary-Point");
        }
        else if(vehicleDPointIn.pointType == EM_MOVE_FREE_QR)
        {
            vcDataItem.sprintf("  Type :%s","QR-Code-Point");
        }
        else if(vehicleDPointIn.pointType == EM_MOVE_FREE_VMARK)
        {
            vcDataItem.sprintf("  Type :%s","VMark-Point");
        }
        else if(vehicleDPointIn.pointType == EM_MOVE_FREE_CU1)
        {
            vcDataItem.sprintf("  Type :%s","CU1-Point");
        }
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("      X = %s mm",QString::number(vehicleDPointIn.posX, 10, 3).toStdString().data());
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("      Y = %s mm",QString::number(vehicleDPointIn.posY, 10, 3).toStdString().data());
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem.sprintf("      R = %s deg",QString::number(vehicleDPointIn.posR, 10, 3).toStdString().data());
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        pointIndexTmp++;
        vcDataItem = QString("};");
        fileInfoList.insert(pointIndexTmp,vcDataItem);
        errorCode = 1;
    }
    return errorCode;
}


void ProgramTextTransfer::addMsg(int messageLevel, std::string  componentName, std::string  messageType,
                           int messageCode, int robotId,
                           int parameter1, int parameter2, int parameter3, int parameter4,QString message)
{
#ifdef D_USE_FOR_CONTROLLER
    Message tmpMsg;
    tmpMsg.MessageLevel = messageLevel;
    tmpMsg.componentClassName = componentName;
    tmpMsg.messageType = messageType;
    tmpMsg.robotId = robotId;
    tmpMsg.messageCode = messageCode;
   // tmpMsg.time = t1.tv_sec;


    QString infomationStr;

    switch(messageCode)
    {
    case 3508:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,文件无法获取！ ").arg(fileName);
        break;
    }
    case 3507:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,PROG或END的标记数量不对！ ").arg(fileName);
        break;
    }
    case 3506:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,P开始点和结束点数据异常！ ").arg(fileName);
        break;
    }
    case 3505:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,P点数据缺少ＸＹＺＷＰＲ信息！ ").arg(fileName);
        break;
    }
    case 3504:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,没找到点和指令数据！ ").arg(fileName);
        break;
    }
    case 3503:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,码跺数据相关，P点数据缺少ＸＹＺＷＰＲ信息！ ")
                .arg(fileName);
        break;
    }

    case 3502:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏，码跺数据相关！ ").arg(fileName);
        break;
    }
    case 3501:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr
                + QObject::tr(",程式文件(%1)内容缺失或损坏,文件缺少属性字段ATTR TCD TCDEND！ ")
                .arg(fileName);
        break;
    }
    case 3500:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr +
                QObject::tr(",程式文件(%1)内容缺失或损坏,文件缺少属性字段ATTR TCD！ ").arg(fileName);
        break;
    }

    case 3008:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",程式名(%1)为空! ").arg(fileName);

    }
        break;
    case 3009:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr +  QObject::tr(",程式文件(%1)不存在!").arg(fileName);

    }
        break;
    case 3010:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",读取文件(%1)指令错误,行号").arg(fileName) + QString::number(parameter1);
    }
        break;


    case 3001:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId) + QObject::tr(",") ;
        infomationStr = infomationStr + QObject::tr(",程式文件(%1)内容缺失或损坏！ ").arg(fileName);
        break;
    }



    default:
    {

    }
    }


    tmpMsg.MessageInformation = infomationStr.toStdString();

    // qDebug()<<"53444444444444444444444"<< tmpMsg.messageCode;
    MessageLog::getInstance()->addMessage(tmpMsg);
#endif
}


int ProgramTextTransfer::readProgram(const QVector<QString> fileInfoList, QString strFilePath,
                                     FileInfo &fileProInfo, QVector<StackInfo> &palletStackInfo,
                                     QVector<PointPro> &pointListOut, QStringList &cmdStrList,
                                     QMap<int, DPoint> &vehicleDPointListOut)
{
    int attrStart,tcdStart, tcdEnd, applStart,commandStart,positionStart, endLine;
    if(1!=readProgramFileStruct(fileInfoList,attrStart,tcdStart, tcdEnd,
                          applStart,commandStart,positionStart, endLine))
    {
        qDebug()<<"ProgramTextTransfer::readProgram failed, file is error!!!readProgramFileStruct";
        return -1;
    }
    readProgramAttribute(attrStart-1,commandStart-1,fileInfoList,strFilePath,fileProInfo);
    if(applStart>0)
    {
         readProgramPalletInfo(applStart,commandStart-1,fileInfoList,palletStackInfo);
    }
    readProgramArmPointInfo_quick(positionStart,endLine,fileInfoList,pointListOut);
    readProgramCommandList(commandStart+1,positionStart-1,fileInfoList,cmdStrList);
//    #ifdef D_USE_ROS
    readProgramDPointData(positionStart,endLine,fileInfoList, vehicleDPointListOut);
//    #endif
    return 1;
}

int ProgramTextTransfer::writeProgram(const FileInfo &fileProInfo,
                                      const QVector<StackInfo> &palletStackInfo,
                                      const QVector<PointPro> &pointList,
                                      const QStringList &cmdStrList,
                                      const QMap<int, DPoint> &vehicleDPointList,
                                      const QVector<int> saveAxisUnit,
                                      int globalDefaultUserNum, int globalDefaultToolNum,
                                      QVector<QString> &fileInfoListOut)
{
    writeProgramAttribute(fileProInfo,cmdStrList.size(),fileInfoListOut);
    writeProgramPalletInfo(globalDefaultUserNum,globalDefaultToolNum,
                                         palletStackInfo,saveAxisUnit,fileInfoListOut);
    writeProgramCommandList(cmdStrList,fileInfoListOut);
    writeProgramArmPointInfo(saveAxisUnit,pointList,fileInfoListOut);
    writeProgramDPointData(vehicleDPointList,fileInfoListOut);

    QString programString = "/END";
    fileInfoListOut.append(programString);
    return 1;
}

int ProgramTextTransfer::readProgramFileStruct(const QVector <QString> fileInfoList, int &attrStart,
                                               int &tcdStart, int &tcdEnd, int &applStart, int &commandStart,
                                                int &positionStart, int &endLine)
{
    QString capStr;
    attrStart = -1;
    tcdStart = -1;
    tcdEnd = -1;
    commandStart = -1;
    positionStart = -1;
    endLine = -1;
    applStart=-1;

    QVector <int> applList;
    applList.clear();


    //文件主要结构提取
        for(int i = 0; i < fileInfoList.size();i++)
        {
            QString str = fileInfoList[i];
            if(fileInfoList[i].contains("/PROG"))
            {
            }
            else if(fileInfoList[i].contains("/ATTR"))
            {
                attrStart = i;
            }
            else if(fileInfoList[i].contains("TCD:"))
            {
                tcdStart = i;
            }
            else if(fileInfoList[i].contains("DEFAULT_GROUP"))
            {
                tcdEnd = i;
                QString pattern("\\s*(DEFAULT_GROUP)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("DEFAULT_GROUP" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("CONTROL_CODE"))
            {
                QString pattern("\\s*(CONTROL_CODE)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("CONTROL_CODE" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("/APPL"))
            {
                applList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**APPL**"<<"i = "<<i<<endl;
            }

            else if(fileInfoList[i].contains("/MN"))
            {
                commandStart = i;
               // qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/MN==="<<commandStart<<endl;
            }
            else if(fileInfoList[i].contains("/POS"))
            {
                positionStart = i;
              //  qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/pos==="<<positionStart<<endl;
            }
            else if(fileInfoList[i].contains("/END"))
            {
                endLine = i;

            }
        }

        if(    attrStart == -1||
               tcdStart == -1||
               tcdEnd == -1||
               commandStart == -1||
               positionStart == -1||
               endLine == -1)
        {
            return -1;
        }
        if(applList.size()>0)
        {
            applStart=applList[0];
        }

        return 1;
}

int ProgramTextTransfer::readProgramArmPointInfo(int startIndex, int endIndex, QVector <QString> fileInfoList,
                                                 QVector<PointPro> &pointListOut)
{
    QString capStr;
    PointPro pointPro;
    pointPro.jointFlag = EM_CF_DEG_TYPE;
    for(int i = startIndex; i <=endIndex;i++)
      {
          if(i < 0)
          {
              qDebug()<<"read file wrong";
              break;
          }
          QString str = fileInfoList[i];
          bool match1 = !fileInfoList[i].contains("DP[");
          bool match2 = !fileInfoList[i].contains("DPL[");
          if(fileInfoList[i].contains("P[") && match1 && match2)
          {
              QString pattern("\\s*(P)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*(\\{)\\s*(.*)");
              QRegExp rx(pattern);
              str.indexOf(rx);
              if("P" == rx.cap(1)
                      &&("[" == rx.cap(2))
                      &&("]" == rx.cap(4)))
              {
                  capStr = rx.cap(3);
                  pointPro.pointNum = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
              }
          }
          else if(fileInfoList[i].contains("GP"))
          {
              pointPro.jointFlag = EM_CF_DEG_TYPE;
              QString pattern("\\s*(GP)\\s*(\\d+)\\s*(:)(.*)");
              QRegExp rx(pattern);
              str.indexOf(rx);
              if("GP" == rx.cap(1))
              {
                  capStr = rx.cap(2);
                  pointPro.groupNum = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
              }
          }
          else if(fileInfoList[i].contains("UF") || fileInfoList[i].contains("UT"))
          {
              QString pattern("\\s*(UF)\\s*(:)\\s*(\\w*)\\s*\\s*(,)\\s*(UT)\\s*(:)\\s*(\\w*)\\s*(,)\\s*(CONFIG)?\\s*(:?)\\s*(.*)");
              QRegExp rx(pattern);
              str.indexOf(rx);

//                  qDebug() << __LINE__ << "====="<<rx.cap(1)<<"===="<<rx.cap(5)<<"\n\n\n";

              if("UF" == rx.cap(1) && ("UT" == rx.cap(5)))
              {
                  capStr = rx.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.ufValue = capStr.toInt();
                  capStr = rx.cap(7);
                  pointPro.utValue = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  capStr = rx.cap(11);
                  pointPro.configString = capStr.toStdString();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
              }
          }
          else if(fileInfoList[i].contains("J"))
          {
//                  QString pattern("\\s*(J)\\s*(\\d+)\\s*(=)\\s*(\\d+.?\\d+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*(\\d+.?\\d+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*(\\d+.?\\d+)\\s*([mmdeg]{2,3})\\s*(.*)");
//                  QRegExp rx(pattern);
//                  str.indexOf(rx);
//                  if("J" == rx.cap(1)&&("=") == rx.cap(3))
//                  {
//                      capStr = rx.cap(4);
//                      qDebug()<<__LINE__<< "*******" <<capStr<<endl;
//                      pointPro.positionValue.push_back(capStr.toFloat());
//                      capStr = rx.cap(10);
//                      qDebug()<<__LINE__<< "*******" <<capStr<<endl;
//                      pointPro.positionValue.push_back(capStr.toFloat());
//                      capStr = rx.cap(16);
//                      qDebug()<<__LINE__<< "*******" <<capStr<<endl;
//                      pointPro.positionValue.push_back(capStr.toFloat());
//                  }

              QString pattern1("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
              QString pattern2("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
              QString pattern3("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");

//                  QString pattern("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,){1,3}(.*)");
              QRegExp rx1(pattern1);
              QRegExp rx2(pattern2);
              QRegExp rx3(pattern3);
              //str.indexOf(rx);
              QString str = fileInfoList[i];

              bool match;
              if((match = rx1.exactMatch(str)) == true)
              {
                  capStr = rx1.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());

                  capStr = rx1.cap(10);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());

                  capStr = rx1.cap(16);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
              }
              else if((match = rx2.exactMatch(str)) == true)
              {
                  capStr = rx2.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());

                  capStr = rx2.cap(10);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
              }
              else if((match = rx3.exactMatch(str)) == true)
              {
                  capStr = rx3.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
              }

          }
          else if(fileInfoList[i].contains('X')||(fileInfoList[i].contains('Y'))||(fileInfoList[i].contains('Z')))
          {
              QString pattern("\\s*(X)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(.*)");
//                  QString pattern("\\s*(X)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(.*)");
              QRegExp rx(pattern);
              str.indexOf(rx);
              if("X" == rx.cap(1)
                      &&("Y" == rx.cap(6))
                      &&("Z" == rx.cap(11)))
              {
                  capStr = rx.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
                  capStr = rx.cap(8);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
                  capStr = rx.cap(13);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
              }

              pointPro.jointFlag = EM_CF_WORLD_TYPE;
          }
          else if(fileInfoList[i].contains('W')||(fileInfoList[i].contains('P'))||(fileInfoList[i].contains('R')))
          {
//    QString pattern("\\s*(W)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(.*)");
              QString pattern("\\s*(W)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(.*)");
              QRegExp rx(pattern);
              str.indexOf(rx);
              if("W" == rx.cap(1)
                      &&("P" == rx.cap(6))
                      &&("R" == rx.cap(11)))
              {
                  capStr = rx.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
                  capStr = rx.cap(8);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
                  capStr = rx.cap(13);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toFloat());
              }
              pointPro.jointFlag = EM_CF_WORLD_TYPE;
          }
          else if(fileInfoList[i].contains('E'))    //外部轴判断部分
          {
              QString pattern1("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
              QString pattern2("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
              QString pattern3("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");

              QRegExp rx1(pattern1);
              QRegExp rx2(pattern2);
              QRegExp rx3(pattern3);
              //str.indexOf(rx);
              QString str = fileInfoList[i];
//                  qDebug()<<__LINE__<<"ex*******"<<str<<endl;

              bool match;
              if((match = rx1.exactMatch(str)) == true)
              {
                  capStr = rx1.cap(4);
//                      qDebug()<< pointPro.pointNum <<" rx1*******"<<capStr<<endl;
                  pointPro.extPositionValue.push_back(capStr.toFloat());

                  capStr = rx1.cap(10);
//                      qDebug()<< pointPro.pointNum <<" rx1*******"<<capStr<<endl;
                  pointPro.extPositionValue.push_back(capStr.toFloat());

                  capStr = rx1.cap(16);
//                      qDebug()<< pointPro.pointNum <<" rx1*******"<<capStr<<endl;
                  pointPro.extPositionValue.push_back(capStr.toFloat());
              }
              else if((match = rx2.exactMatch(str)) == true)
              {
                  capStr = rx2.cap(4);
//                      qDebug()<< pointPro.pointNum <<" rx2*******"<<capStr<<endl;
                  pointPro.extPositionValue.push_back(capStr.toFloat());

                  capStr = rx2.cap(10);
//                      qDebug()<< pointPro.pointNum <<" rx2*******"<<capStr<<endl;
                  pointPro.extPositionValue.push_back(capStr.toFloat());
              }
              else if((match = rx3.exactMatch(str)) == true)
              {
                  capStr = rx3.cap(4);
//                      qDebug()<< pointPro.pointNum <<" rx3*******"<<capStr<<endl;
                  pointPro.extPositionValue.push_back(capStr.toFloat());
              }
          }
          else if(fileInfoList[i].contains("};"))
          {
              pointListOut.push_back(pointPro);
              pointPro.positionValue.clear();       //清空
              pointPro.extPositionValue.clear();    //清空
          }
      }
    return 1;
}
enum E_POINT_STAGE
{
    E_POINT_STAGE_NONE,
    E_POINT_STAGE_P,
    E_POINT_STAGE_GP,
    E_POINT_STAGE_UF,
    E_POINT_STAGE_COORDVALUE_X,
    E_POINT_STAGE_COORDVALUE_W,
    E_POINT_STAGE_JVALUE,
    E_POINT_STAGE_END,
};
int ProgramTextTransfer::readProgramArmPointInfo_quick(int startIndex, int endIndex,
                                      QVector<QString> fileInfoList, QVector<PointPro> &pointListOut)
{
    if(startIndex < 0)
    {
        qDebug()<<"readProgramArmPointInfo_quick read file wrong";
        return -1;
    }
    QString capStr;
    PointPro pointPro;
    pointPro.jointFlag = EM_CF_DEG_TYPE;
    E_POINT_STAGE tmpStage=E_POINT_STAGE_NONE;
    QString str;

    QRegExp rx_p("P\\[(\\d*)\\]\\{");

    QString pattern("\\s*(UF)\\s*(:)\\s*(\\w*)\\s*\\s*(,)\\s*(UT)\\s*(:)\\s*(\\w*)\\s*(,)\\s*(CONFIG)?\\s*(:?)\\s*(.*)");
    QRegExp rx_uf(pattern);

    QString pattern1("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
    QString pattern2("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
    QString pattern3("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
//                  QString pattern("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,){1,3}(.*)");
    QRegExp rx1(pattern1);
    QRegExp rx2(pattern2);
    QRegExp rx3(pattern3);

    //
    QString pattern_coordX("\\s*(X)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(.*)");
//                  QString pattern("\\s*(X)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(.*)");
    QRegExp rx_coordX(pattern_coordX);

    //
    QString pattern_coordW("\\s*(W)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(.*)");
    QRegExp rx_coordW(pattern_coordW);

    for(int i = startIndex; i <=endIndex;i++)
      {

          str = fileInfoList[i];
          //判断行类型
          switch (tmpStage) {
          case E_POINT_STAGE_END:
          case E_POINT_STAGE_NONE:
          if(rx_p.exactMatch(str))
          {
              tmpStage=E_POINT_STAGE_P;
          }
          break;
          case E_POINT_STAGE_P:
          tmpStage=E_POINT_STAGE_GP;
          break;
          case E_POINT_STAGE_GP:
          tmpStage=E_POINT_STAGE_UF;
          break;
          case E_POINT_STAGE_UF:
          if(str.contains("J"))
          {
              tmpStage=E_POINT_STAGE_JVALUE;
          }
          else
          {
              if(str.contains("X"))
              {
                  tmpStage=E_POINT_STAGE_COORDVALUE_X;
              }
              else
              {
                  tmpStage=E_POINT_STAGE_COORDVALUE_W;
              }

          }
          break;
          case E_POINT_STAGE_COORDVALUE_X:
          case E_POINT_STAGE_COORDVALUE_W:
          {
              if(str.contains("X"))
              {
                  tmpStage=E_POINT_STAGE_COORDVALUE_X;
              }
              else
              {
                  tmpStage=E_POINT_STAGE_COORDVALUE_W;
              }
              if(str.contains("}"))
              {
                  tmpStage=E_POINT_STAGE_END;
              }
          }
              break;
          case E_POINT_STAGE_JVALUE:
              if(str.contains("}"))
              {
                  tmpStage=E_POINT_STAGE_END;
              }

          break;
          default:
              break;
          }
          //解析行
          switch (tmpStage) {
          case E_POINT_STAGE_NONE:
          break;
          case E_POINT_STAGE_P:
          pointPro.pointNum = rx_p.cap(1).toInt();
          break;
          case E_POINT_STAGE_GP:
          break;
          case E_POINT_STAGE_UF:
          {
              str.indexOf(rx_uf);
              if("UF" == rx_uf.cap(1) && ("UT" == rx_uf.cap(5)))
              {
                  capStr = rx_uf.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.ufValue = capStr.toInt();
                  capStr = rx_uf.cap(7);
                  pointPro.utValue = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  capStr = rx_uf.cap(11);
                  pointPro.configString = capStr.toStdString();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
              }
          }
          break;
          case E_POINT_STAGE_COORDVALUE_X:
          {

              str.indexOf(rx_coordX);
              if("X" == rx_coordX.cap(1)
                      &&("Y" == rx_coordX.cap(6))
                      &&("Z" == rx_coordX.cap(11)))
              {
                  capStr = rx_coordX.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
                  capStr = rx_coordX.cap(8);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
                  capStr = rx_coordX.cap(13);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
              }

              pointPro.jointFlag = EM_CF_WORLD_TYPE;
          }
              break;
          case E_POINT_STAGE_COORDVALUE_W:
          {

              str.indexOf(rx_coordW);
              if("W" == rx_coordW.cap(1)
                      &&("P" == rx_coordW.cap(6))
                      &&("R" == rx_coordW.cap(11)))
              {
                  capStr = rx_coordW.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
                  capStr = rx_coordW.cap(8);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
                  capStr = rx_coordW.cap(13);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
              }
              pointPro.jointFlag = EM_CF_WORLD_TYPE;
          }
              break;
          case E_POINT_STAGE_JVALUE:
          {
              pointPro.jointFlag = EM_CF_DEG_TYPE;
              bool match;
              if((match = rx1.exactMatch(str)) == true)
              {
                  capStr = rx1.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());

                  capStr = rx1.cap(10);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());

                  capStr = rx1.cap(16);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
              }
              else if((match = rx2.exactMatch(str)) == true)
              {
                  capStr = rx2.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());

                  capStr = rx2.cap(10);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
              }
              else if((match = rx3.exactMatch(str)) == true)
              {
                  capStr = rx3.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  pointPro.positionValue.push_back(capStr.toDouble());
              }
          }

          break;
          case E_POINT_STAGE_END:
          {
              pointListOut.push_back(pointPro);
              pointPro.positionValue.clear();       //清空
              pointPro.extPositionValue.clear();    //清空
              tmpStage=E_POINT_STAGE_NONE;
          }

          break;
          default:
              break;
          }
      }
    return 1;
}

int ProgramTextTransfer::readProgramAttribute(int startIndex, int endIndex, QVector<QString> fileInfoList, QString strFilePath,
                                               FileInfo &fileProInfo)
{
    QString capStr;

    int attrStart = 0;
    int tcdStart = 0;
    int tcdEnd = 0;
    int commandStart = 0;
    int positionStart = 0;
    int endLine = 0;

    QVector <int> applList;
    applList.clear();


    //文件主要结构提取
        for(int i = startIndex; i <=endIndex;i++)
        {
//            qDebug()<<"check "<<fileInfoList[i];
//            if(ENUM_COMMAND_RESET == *engineStatus)
//            {
//                return 1;
//            }
            QString str = fileInfoList[i];
            if(fileInfoList[i].contains("/PROG"))
            {
//                fileCount++;
                QString pattern("\\s*(/PROG)\\s*(\\w*)\\s*(.*)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("/PROG" == rx.cap(1))
                {
                    capStr = rx.cap(2);
                    fileProInfo.programName = strFilePath.toStdString();

//                    qDebug()<<__LINE__<<"*******"<<strFilePath<<endl;
                }
            }
            else if(fileInfoList[i].contains("/ATTR"))
            {
                attrStart = i;
            }
            else if(fileInfoList[i].contains("TCD:"))
            {
                tcdStart = i;
            }
            else if(fileInfoList[i].contains("DEFAULT_GROUP"))
            {
                tcdEnd = i;
                QString pattern("\\s*(DEFAULT_GROUP)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("DEFAULT_GROUP" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("CONTROL_CODE"))
            {
                QString pattern("\\s*(CONTROL_CODE)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("CONTROL_CODE" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("/APPL"))
            {
                applList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**APPL**"<<"i = "<<i<<endl;
            }

            else if(fileInfoList[i].contains("/MN"))
            {
                commandStart = i;
               // qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/MN==="<<commandStart<<endl;
            }
            else if(fileInfoList[i].contains("/POS"))
            {
                positionStart = i;
              //  qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/pos==="<<positionStart<<endl;
            }
            else if(fileInfoList[i].contains("/END"))
            {
                endLine = i;
//                fileCount++;
            }
        }

        for(int i = 0; i < fileInfoList.size();i++)
        {
 //               if(ENUM_COMMAND_RESET == *engineStatus)
 //               {
 //                   return 1;
 //               }
             QString str = fileInfoList[i];
             if(fileInfoList[i].contains("STACK_SIZE"))
             {
                 QString pattern("\\s*(TCD:)\\s*(STACK_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                 QRegExp rx(pattern);
                 str.indexOf(rx);
                 if("STACK_SIZE" == rx.cap(2))
                 {
                     capStr = rx.cap(4);
                     fileProInfo.tcdStackSize = capStr.toInt();
 //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                 }
             }
             else if(fileInfoList[i].contains("TASK_PRIORITY"))
             {
                 QString pattern("\\s*(TASK_PRIORITY)\\s*(=)\\s*(\\w*)\\s*(.*)");
                 QRegExp rx(pattern);
                 str.indexOf(rx);
                 if("TASK_PRIORITY" == rx.cap(1))
                 {
                     capStr = rx.cap(3);
                     fileProInfo.tcdTaskPriority = capStr.toInt();
 //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                 }
             }
             else if(fileInfoList[i].contains("TIME_SLICE"))
             {
                 QString pattern("\\s*(TIME_SLICE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                 QRegExp rx(pattern);
                 str.indexOf(rx);
                 if("TIME_SLICE" == rx.cap(1))
                 {
                     capStr = rx.cap(3);
                     fileProInfo.tcdTimeSlice = capStr.toInt();
 //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                 }
             }
             else if(fileInfoList[i].contains("BUSY_LAMP_OFF"))
             {
                 QString pattern("\\s*(BUSY_LAMP_OFF)\\s*(=)\\s*(\\w*)\\s*(.*)");
                 QRegExp rx(pattern);
                 str.indexOf(rx);
                 if("BUSY_LAMP_OFF" == rx.cap(1))
                 {
                     capStr = rx.cap(3);
                     fileProInfo.tcdBusyLampOff = capStr.toInt();
 //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                 }
             }
             else if(fileInfoList[i].contains("ABORT_REQUEST"))
             {
                 QString pattern("\\s*(ABORT_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                 QRegExp rx(pattern);
                 str.indexOf(rx);
                 if("ABORT_REQUEST" == rx.cap(1))
                 {
                     capStr = rx.cap(3);
                     fileProInfo.tcdAbortRequest = capStr.toInt();
 //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                 }
             }
             else if(fileInfoList[i].contains("PAUSE_REQUEST"))
             {
                 QString pattern("\\s*(PAUSE_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                 QRegExp rx(pattern);
                 str.indexOf(rx);
                 if("PAUSE_REQUEST" == rx.cap(1))
                 {
                     capStr = rx.cap(3);
                     fileProInfo.tcdPauseRequest = capStr.toInt();
 //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                 }
             }
        }


           for(int i = 0;i < fileInfoList.size();i++)
           {

               QString str = fileInfoList[i];
               if(fileInfoList[i].startsWith("OWNER"))
               {
                    QString pattern("\\s*(OWNER)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("OWNER" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.owner = capStr.toStdString();
                        //qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("COMMENT"))
               {
                    QString pattern("\\s*(COMMENT)\\s*(=)\\s*([\\w\\s]*)\\s*(.*)");//2017.02.17修改支持空格
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("COMMENT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.comment = capStr.toStdString();
                        //qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("PROG_SIZE"))
               {
                     QString pattern("\\s*(PROG_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                     QRegExp rx(pattern);
                     str.indexOf(rx);
                     if("PROG_SIZE" == rx.cap(1))
                     {
                         capStr = rx.cap(3);
                         fileProInfo.programSize = capStr.toInt();
    //                         qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                     }
               }
               else if(fileInfoList[i].startsWith("CREATE"))
               {
                    QString pattern("\\s*(CREATE)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("CREATE" == rx.cap(1))
                    {
                        QString timeStr = "";
                        capStr = rx.cap(4);
                        timeStr += capStr + "-";
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(6);
                        timeStr += capStr + "-";
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(8) + " ";
                        timeStr += capStr;
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(10) + ":";
                        timeStr += capStr;
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(12) + ":";
                        timeStr += capStr;
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(14);
                        timeStr += capStr;
    //                        qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                        fileProInfo.createTime = timeStr.toStdString();
                    }
               }
               else if(fileInfoList[i].startsWith("MODIFIED"))
               {
                   QString pattern("\\s*(MODIFIED)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("MODIFIED" == rx.cap(1))
                   {
                       QString timeStr = "";
                       capStr = rx.cap(4);
                       timeStr += capStr + "-";
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(6);
                       timeStr += capStr + "-";
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(8);
                       timeStr += capStr + " ";
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(10) + ": ";
                       timeStr += capStr;
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(12) + ": ";
                       timeStr += capStr;
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(14);
                       timeStr += capStr;
    //                       qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                       fileProInfo.modifiTime = timeStr.toStdString();
                   }
               }
               else if(fileInfoList[i].startsWith("FILE_NAME"))
               {
                   QString pattern("\\s*(FILE_NAME)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("FILE_NAME" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfo.fileName = capStr.toStdString();
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("VERSION"))
               {
                   QString pattern("\\s*(VERSION)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("VERSION" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfo.version = capStr.toStdString();
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }

               }
               else if(fileInfoList[i].startsWith("LINE_COUNT"))
               {
                   QString pattern("\\s*(LINE_COUNT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("LINE_COUNT" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfo.lineCount = capStr.toInt();
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("MEMORY_SIZE"))
               {
                    QString pattern("\\s*(MEMORY_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("MEMORY_SIZE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.memorySize = capStr.toInt();
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("PROTECT"))
               {
                    QString pattern("\\s*(PROTECT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PROTECT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.protectPro = capStr.toStdString();
    //                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("TEMPLATETYPE"))
               {
                    QString pattern("\\s*(TEMPLATETYPE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);

                    if("TEMPLATETYPE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.templateType = capStr.toInt();
    //                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
            }
     return 1;
}
int ProgramTextTransfer::readProgramAttributeQuick(const QVector<QString> fileInfoList, QString strFilePath,
                                                   FileInfo &fileProInfoQuick)
{

    QString capStr;

    int fileCount = 0;

    int attrStart = 0;
    int tcdStart = 0;
    int tcdEnd = 0;

        //分析
        for(int i = 0; i < fileInfoList.size();i++)
        {
            QString str = fileInfoList[i];
            if(fileInfoList[i].contains("/PROG"))
            {
                fileCount++;
                QString pattern("\\s*(/PROG)\\s*(\\w*)\\s*(.*)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("/PROG" == rx.cap(1))
                {
                    capStr = rx.cap(2);
                    fileProInfoQuick.programName = strFilePath.toStdString();
//                    qDebug()<<__LINE__<<"*******"<<strFilePath<<endl;
                }
            }
            else if(fileInfoList[i].contains("/ATTR"))
            {
                attrStart = i;
            }
            else if(fileInfoList[i].contains("TCD:"))
            {
                tcdStart = i;
            }
            else if(fileInfoList[i].contains("DEFAULT_GROUP"))
            {
                tcdEnd = i;
                QString pattern("\\s*(DEFAULT_GROUP)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("DEFAULT_GROUP" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("CONTROL_CODE"))
            {
                QString pattern("\\s*(CONTROL_CODE)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("CONTROL_CODE" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
                fileCount++;
            }
        }

        //提取内容
        if(2 == fileCount)
        {
//            qDebug()<<__FUNCTION__<<"******"<<__LINE__<<"**commandStart**"<<commandStart<<
//                   "**positionStart**"<<positionStart<<"**endLine***"<<endLine<<endl;
           for(int i = attrStart + 1;i < tcdStart;i++)
           {
               QString str = fileInfoList[i];
               if(fileInfoList[i].startsWith("OWNER"))
               {
                    QString pattern("\\s*(OWNER)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("OWNER" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.owner = capStr.toStdString();
                        //qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("COMMENT"))
               {
                    QString pattern("\\s*(COMMENT)\\s*(=)\\s*([\\w\\s]*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("COMMENT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.comment = capStr.toStdString();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }

               }
               else if(fileInfoList[i].startsWith("PROG_SIZE"))
               {
                     QString pattern("\\s*(PROG_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                     QRegExp rx(pattern);
                     str.indexOf(rx);
                     if("PROG_SIZE" == rx.cap(1))
                     {
                         capStr = rx.cap(3);
                         fileProInfoQuick.programSize = capStr.toInt();
//                         qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                     }
               }
               else if(fileInfoList[i].startsWith("CREATE"))
               {
                    QString pattern("\\s*(CREATE)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("CREATE" == rx.cap(1))
                    {
                        QString timeStr = "";
                        capStr = rx.cap(4);
                        timeStr += capStr + "-";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(6);
                        timeStr += capStr + "-";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(8);
                        timeStr += capStr + " ";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(10) + ":";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(12) + ":";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(14);
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                        fileProInfoQuick.createTime = timeStr.toStdString();
                    }
               }
               else if(fileInfoList[i].startsWith("MODIFIED"))
               {
                   QString pattern("\\s*(MODIFIED)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("MODIFIED" == rx.cap(1))
                   {
                       QString timeStr = "";
                       capStr = rx.cap(4);
                       timeStr += capStr + "-";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(6);
                       timeStr += capStr + "-";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(8);
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(10) + ": ";
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(12) + ": ";
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(14);
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                       fileProInfoQuick.modifiTime = timeStr.toStdString();
                   }
               }
               else if(fileInfoList[i].startsWith("FILE_NAME"))
               {
                   QString pattern("\\s*(FILE_NAME)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("FILE_NAME" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfoQuick.fileName = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("VERSION"))
               {
                   QString pattern("\\s*(VERSION)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("VERSION" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfoQuick.version = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }

               }
               else if(fileInfoList[i].startsWith("LINE_COUNT"))
               {
                   QString pattern("\\s*(LINE_COUNT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("LINE_COUNT" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfoQuick.lineCount = capStr.toInt();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("MEMORY_SIZE"))
               {
                    QString pattern("\\s*(MEMORY_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("MEMORY_SIZE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.memorySize = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("PROTECT"))
               {
                    QString pattern("\\s*(PROTECT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PROTECT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.protectPro = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("TEMPLATETYPE"))
               {
                    QString pattern("\\s*(TEMPLATETYPE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);

                    if("TEMPLATETYPE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.templateType = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
            }
           for(int i = tcdStart; i < tcdEnd;i++)
           {
//               if(ENUM_COMMAND_RESET == *engineStatus)
//               {
//                   return 1;
//               }
                QString str = fileInfoList[i];
                if(fileInfoList[i].contains("STACK_SIZE"))
                {
                    QString pattern("\\s*(TCD:)\\s*(STACK_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("STACK_SIZE" == rx.cap(2))
                    {
                        capStr = rx.cap(4);
                        fileProInfoQuick.tcdStackSize = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("TASK_PRIORITY"))
                {
                    QString pattern("\\s*(TASK_PRIORITY)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("TASK_PRIORITY" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdTaskPriority = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("TIME_SLICE"))
                {
                    QString pattern("\\s*(TIME_SLICE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("TIME_SLICE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdTimeSlice = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("BUSY_LAMP_OFF"))
                {
                    QString pattern("\\s*(BUSY_LAMP_OFF)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("BUSY_LAMP_OFF" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdBusyLampOff = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("ABORT_REQUEST"))
                {
                    QString pattern("\\s*(ABORT_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("ABORT_REQUEST" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdAbortRequest = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("PAUSE_REQUEST"))
                {
                    QString pattern("\\s*(PAUSE_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PAUSE_REQUEST" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdPauseRequest = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
           }

           qDebug()<<QString::fromStdString(fileProInfoQuick.createTime);
        }

    return 0;//完成
}


int ProgramTextTransfer::readProgramPalletInfo(int startIndex, int endIndex,
                                               QVector <QString> fileInfoList,
                                               QVector<StackInfo> &palletStackInfo)
{

        return 1;
}

int ProgramTextTransfer::readProgramCommandList(int startIndex, int endIndex, QVector <QString> fileInfoList,
                                                QStringList &cmdStrList)
{
    QString capStr;
    QString str;
    QString pattern1("\\s*(\\d+)\\s*(:)\\s*(.*)");
    QString pattern2("\\s*(\\/\\/)\\s*(.*)");
    QRegExp rx1(pattern1);
    QRegExp rx2(pattern2);
    for(int i = startIndex; i <=endIndex;i++)
    {
        str = fileInfoList[i];

        str.indexOf(rx1);
        str.indexOf(rx2);
        if(":" == rx1.cap(2))
        {
            capStr = rx1.cap(1);
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
            capStr = rx1.cap(3);
            cmdStrList.append(capStr);
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
        }
        else if("//" == rx2.cap(1))
        {
            capStr = str;
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
            cmdStrList.append(capStr);
        }
        else//2017-03-23 缺少行编号,正常读取,但是会有会控制器的报错提示
        {
            capStr = str;
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
            cmdStrList.append(capStr);
        }
    }
    return 1;
}

int ProgramTextTransfer::writeProgramDPointData(const QMap<int, DPoint> &vehicleDPointList,
                                                QVector<QString> &programStrList)
{
//    QString programStr;
    // 加锁，保护数据
//    mutex.lock();
    // 遍历将DPoint点位数据写入到文件
    QString tmpPointTypeStr;
    for(int dpIndex = 0; dpIndex < vehicleDPointList.keys().count(); dpIndex++)
    {
        if(vehicleDPointList.values().at(dpIndex).pointType == EM_MOVE_FREE_DP)
        {
            tmpPointTypeStr = "Ordinary-Point";
        }
        else if(vehicleDPointList.values().at(dpIndex).pointType == EM_MOVE_FREE_QR)
        {
            tmpPointTypeStr = "QR-Code-Point";
        }
        else if(vehicleDPointList.values().at(dpIndex).pointType == EM_MOVE_FREE_VMARK)
        {
            tmpPointTypeStr = "VMark-Point";
        }
        else if(vehicleDPointList.values().at(dpIndex).pointType == EM_MOVE_FREE_CU1)
        {
            tmpPointTypeStr = "CU1-Point";
        }
        else
        {
            tmpPointTypeStr = "Unknow-Point";
        }



        programStrList.append(QString("%1%2%3").arg("DP[").arg(QString::number(vehicleDPointList.values().at(dpIndex).dpIndex)).arg("]{"));
        programStrList.append(QString("%1%2").arg("  MapName : ").arg(QString::fromStdString(vehicleDPointList.values().at(dpIndex).mapName).remove(QRegExp("\\s"))));
        programStrList.append(QString("%1%2").arg("    Type  : ").arg(tmpPointTypeStr));
        programStrList.append(QString("%1%2%3").arg("      X = ").arg(QString::number(vehicleDPointList.values().at(dpIndex).posX, 10, 3)).arg(" mm"));
        programStrList.append(QString("%1%2%3").arg("      Y = ").arg(QString::number(vehicleDPointList.values().at(dpIndex).posY, 10, 3)).arg(" mm"));
        programStrList.append(QString("%1%2%3").arg("      R = ").arg(QString::number(vehicleDPointList.values().at(dpIndex).posR, 10, 3)).arg(" deg"));
//        programStr = "DP[" + QString::number(vehicleDPointList.keys().at(dpIndex)) + "]{";
//        programStr = "  MapName : " + QString::fromStdString(vehicleDPointList.values().at(dpIndex).mapName).remove(QRegExp("\\s"));
//        programStr = "      Y = " + QString::number(vehicleDPointList.values().at(dpIndex).posY, 10, 3) + " mm";
//        programStr = "      X = " + QString::number(vehicleDPointList.values().at(dpIndex).posX, 10, 3) + " mm";
//        programStr = "      R = " + QString::number(vehicleDPointList.values().at(dpIndex).posR, 10, 3) + " deg";
//        programStr = "";
//        programStrList.append(programStr);
//        programStr = "};";
        programStrList.append("};");
    }
//    mutex.unlock();
    return 1;

}

int ProgramTextTransfer::readProgramDPointData(int startIndex, int endIndex,
                                               QVector<QString> fileInfoList,
                                               QMap<int, DPoint> &vehicleDPointListOut)
{

    DPoint dPointTemp;
    bool match;
    QString dPointPat;
    QRegExp rxDPoint;
    // 每次读取文件清空容器，以保存新数据
    vehicleDPointListOut.clear();

    for(int i = startIndex; i <= endIndex; i++)
    {
        if((fileInfoList[i].contains("DP[")) && (fileInfoList[i].contains("]{")) )
        {
            dPointPat = "\\s*(DP\\[(\\d+)\\])(\\{)";                    //  DP[]{
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.dpIndex = rxDPoint.cap(2).toInt();
            }
        }
        else if(fileInfoList[i].contains("MapName"))
        {
            dPointPat = "\\s*(MapName)\\s*(:)\\s*(.*)\\s*";             // MapName :
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.mapName = rxDPoint.cap(3).toStdString();
            }
        }
        else if( (fileInfoList[i].contains("X")) && (fileInfoList[i].contains("mm")) )
        {
            dPointPat = "\\s*(X)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(mm)";      // X = ... mm
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posX = rxDPoint.cap(3).toDouble();
            }
        }
        else if( (fileInfoList[i].contains("Y")) && (fileInfoList[i].contains("mm")))
        {
            dPointPat = "\\s*(Y)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(mm)";      // Y = ... mm
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posY = rxDPoint.cap(3).toDouble();
            }
        }
        else if(fileInfoList[i].contains("Type"))
        {
             dPointPat = "\\s*(Type)\\s*(:)\\s*(\\S*)\\s*";
             rxDPoint.setPattern(dPointPat);

             if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
             {
                if(rxDPoint.cap(3)=="VMark-Point")
                {
                    dPointTemp.pointType = EM_MOVE_FREE_VMARK;
                }
                else if(rxDPoint.cap(3) == "QR-Code-Point")
                {
                   dPointTemp.pointType = EM_MOVE_FREE_QR;
                }
                else if(rxDPoint.cap(3) == "Ordinary-Point")
                {
                   dPointTemp.pointType = EM_MOVE_FREE_DP;
                }
                else if(rxDPoint.cap(3) == "CU1-Point")
                {
                     dPointTemp.pointType = EM_MOVE_FREE_CU1;
                }
                else
                {
                    dPointTemp.pointType = EM_MOVE_FREE_NOPOINT;
                }
             }
        }
        else if( (fileInfoList[i].contains("R")) && (fileInfoList[i].contains("deg")) )
        {
            dPointPat = "\\s*(R)\\s*(=)\\s*(\\-?\\d*\\.\\d+)\\s*(deg)";     // R = ... deg
            rxDPoint.setPattern(dPointPat);

            if((match = rxDPoint.exactMatch(fileInfoList[i])) == true)
            {
                dPointTemp.posR = rxDPoint.cap(3).toDouble();
//                mutex.lock();
                vehicleDPointListOut.insert(dPointTemp.dpIndex, dPointTemp);
//                mutex.unlock();

                MOVE_FREE_POINT_TYPE pointType=vehicleDPointListOut.value(dPointTemp.dpIndex).pointType;

                qDebug() << "DP[" << dPointTemp.dpIndex << "]{";
                qDebug() << "    MapName   :" << QString::fromStdString(vehicleDPointListOut.value(dPointTemp.dpIndex).mapName);
                qDebug() << "   Point-Type :" << pointType;
                qDebug() << "            X :" << vehicleDPointListOut.value(dPointTemp.dpIndex).posX;
                qDebug() << "            Y :" << vehicleDPointListOut.value(dPointTemp.dpIndex).posY;
                qDebug() << "            R :" << vehicleDPointListOut.value(dPointTemp.dpIndex).posR;
                qDebug() << "   }";
            }
        }

    }
    return 1;
}

int ProgramTextTransfer::writeProgramAttribute(const FileInfo  &fileProInfo, int cmdLineSize,
                                               QVector <QString> &programList)
{
    QString programString;
    programString = "/PROG";
    programList.append(programString);
    programString = "/ATTR";
    programList.append(programString);
    programString = "OWNER  =";
    programString = programString + QString::fromStdString(fileProInfo.owner) + ";";
    programList.append(programString);
    programString = "COMMENT  =";
    programString = programString + QString::fromStdString(fileProInfo.comment) + ";";
    programList.append(programString);
    programString = "PROG_SIZE  =";
    programString = programString + QString::number(0) + ";";
    programList.append(programString);
    programString = "CREATE  =";
    programString = programString + QString::fromStdString(fileProInfo.createTime) + ";";
    programList.append(programString);
    programString = "MODIFIED  =";
    programString = programString + QString::fromStdString(fileProInfo.modifiTime) + ";";
    programList.append(programString);
    programString = "FILE_NAME  =";
    programString = programString + QString::fromStdString(fileProInfo.fileName) + ";";
    programList.append(programString);
    programString = "VERSION  =";
    int newVersion=QString::fromStdString(fileProInfo.version).toInt()+1;
    programString = programString + QString::number(newVersion) + " ;";
    programList.append(programString);
    programString = "LINE_COUNT  =";
    programString = programString + QString::number(cmdLineSize) + ";";//此处原本为控制器接收后的指令长度(即要保存的缓存长度)
    programList.append(programString);
    programString = "MEMORY_SIZE  =";
    programString = programString + QString::number(0) + ";";
    programList.append(programString);
    programString = "PROTECT  =";
    programString = programString + "READ_WRITE;";
    programList.append(programString);
    programString = "TEMPLATETYPE  =";
    programString = programString + QString::number(fileProInfo.templateType) + ";";
    programList.append(programString);
    programString = "TCD: STACK_SIZE  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "TASK_PRIORITY  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "TIME_SLICE  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "BUSY_LAMP_OFF  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "ABORT_REQUEST  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "PAUSE_REQUEST  =";
    programString = programString + QString::number(0) + ";";
    programList.append(programString);
    programString = "DEFAULT_GROUP  =";
    programString = programString + ";";
    programList.append(programString);
    programString = "CONTROL_CODE  =";
    programString = programString + ";";
    programList.append(programString);
    programString = "/APPL";
    programList.append(programString);
    programString = "/MN";
    programList.append(programString);
    return 1;
}

int ProgramTextTransfer::writeProgramPalletInfo(int globalDefaultUserNum,int globalDefaultToolNum,
                                                const QVector <StackInfo> &palletStackInfo,
                                const QVector<int> saveAxisUnit, QVector <QString> &programList)
{


    return 1;
}

int ProgramTextTransfer::writeProgramArmPointInfo(QVector <int > saveAxisUnit,
                                                  const QVector <PointPro>& getPointProList,
                                                  QVector <QString> &programList)
{

    QString programString;

    QVector <QString> tmpUnit;//单位数据 缓存
    tmpUnit.clear();//暂时先修改普通P点的单位 码垛未修改
    for(int j = 0; j < D_ROBOT_AXIS_MAX;j++)//点数据最多是D_ROBOT_AXIS_MAX个
    {
        if(j<saveAxisUnit.size())//实际有的轴 eg 4个
        {
            if(saveAxisUnit[j] == EM_AXIS_DEG)
            {
                tmpUnit.append("deg,");
            }
            else
            {
                tmpUnit.append("mm,");
            }
        }
        else
        {
            tmpUnit.append("mm,");
        }
    }//tmpUnit.size = 6 后面使用的时候,需要判断是否 <= 6

    QString jointLineStr;


    for(int i = 0; i < getPointProList.size();i++)
    {
        //此处为按顺序,如果点编号错误,那么保存一次后也会纠正正常?
        programString = "P[" + QString::number(i+1) + "]{";//programString = "P[" + QString::number(getPointProList[i].pointNum) + "]{";
//            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
        programList.append(programString);
        programString = "   GP"+QString::number(1) + ":";
//            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
        programList.append(programString);

        if(getPointProList[i].jointFlag == EM_CF_WORLD_TYPE)
        {
            programString = "       UF :" + QString::number(getPointProList[i].ufValue) +
                    ", UT :" + QString::number(getPointProList[i].utValue) + "," + "       CONFIG:"+
                    QString::fromStdString(getPointProList[i].configString);
        }
        else if(getPointProList[i].jointFlag == EM_CF_DEG_TYPE)
        {
            programString = "       UF :" + QString::number(getPointProList[i].ufValue) +
                    ", UT :" + QString::number(getPointProList[i].utValue) + "," + "       "+
                    QString::fromStdString(getPointProList[i].configString);
        }
//            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
        programList.append(programString);

//            qDebug()<<__FUNCTION__<<"==="<<__LINE__<<
//                      "==USEER==="<<getPointProList[i].ufValue<<
//                      "==TOOL===="<<getPointProList[i].utValue<<endl;

        programString = "";
        for(int j = 0; j < getPointProList[i].positionValue.size();j++)
        {
//                qDebug() <<"****j**"<<j<<"***jointFlag***"<<getPointProList[i].jointFlag<<endl;
            if(getPointProList[i].jointFlag == EM_CF_WORLD_TYPE)
            {
                if(j == EM_CF_X)
                {
                    programString = programString + "       X =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " mm,";
                }
                else if(j == EM_CF_Y)
                {
                    programString = programString + "       Y =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " mm,";
                }
                else if(j == EM_CF_Z)
                {
                    programString = programString + "       Z =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " mm,";

                    programList.append(programString);//加一行
                    programString = "";//此处的空等价于换行了
                }
                else if(j == EM_CF_W)
                {
                    programString = programString + "       W =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " deg,";
                }
                else if(j == EM_CF_P)
                {
                    programString = programString + "       P =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " deg,";
                }
                else if(j == EM_CF_R)
                {
                    programString = programString + "       R =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " deg,";
                    programList.append(programString);
                    programString = "";
                }
            }
            else if(getPointProList[i].jointFlag == EM_CF_DEG_TYPE)
            {
                if(0 == j % 3 )
                {
                    if(0<j)
                    {
                        programList.append(jointLineStr);
                    }
                    jointLineStr= "       J" + QString::number(j + 1) + "=       " +
                            QString::number(getPointProList[i].positionValue[j])+tmpUnit[j];

                }
                else
                {

                    jointLineStr += "       J" + QString::number(j + 1) + "=       " +
                            QString::number(getPointProList[i].positionValue[j])+tmpUnit[j];

                }


                if((j == getPointProList[i].positionValue.size() - 1) )
                {
                    programList.append(jointLineStr);
                }
            }
        }

        //外部轴数据插入
        programString = "";

        for(int j = 0; j < getPointProList[i].extPositionValue.size();j++)
        {
            //not used
        }

        programString = "};";
        programList.append(programString);
    }
    return 1;
}

int ProgramTextTransfer::writeProgramCommandList(const QStringList &cmdStrWriteList,
                                                 QVector <QString> &programList)
{
    QString programString;
    for(int i = 0;i < cmdStrWriteList.size();i++)
    {
        programString = QString::number(i+1) + ":" + cmdStrWriteList[i];
        programList.append(programString);
//        qDebug()<<__FUNCTION__<<"****"<<__LINE__<<"***"<<cmdStringList[i];
    }
    programString = "/POS";
    programList.append(programString);
    return 1;
}

